package com.iwy.hadoop.mapreduce;

import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Reducer;

import java.io.IOException;

/**
 * @Author weibi
 * @Date 2021/1/21 9:39
 * @Description //TODO
 */
public class WordcountReducer extends Reducer<Text, IntWritable, Text, IntWritable> {


    @Override
    protected void reduce(Text key, Iterable<IntWritable> values, Context context)
            throws IOException, InterruptedException {


        // 求和
        int sum = 0;
        for (IntWritable value : values) {
            sum += value.get();
        }
        // 写入
        IntWritable v = new IntWritable();
        v.set(sum);
        context.write(key, v);
    }
}
